import { APIHost } from './base';
import { apiClient } from '@/utils/apiClient';

export const GoodsService = {
    /**
     * 添加商品
     * @param {Object} goodsData - 商品数据
     * @returns {Promise<Object>} 添加结果
     */
    async addGoods(goodsData) {
        return apiClient.post('/api/goods/addGoods', goodsData);
    },

    /**
     * 获取商品列表
     * @param {string} kind - 商品类别
     * @param {string} fromSn - 发布人
     * @param {string} title - 商品名称关键字
     * @param {number} status - 商品状态
     * @param {number} limit - 限制数量
     * @param {number} offset - 偏移量
     * @returns {Promise<Object>} 商品列表
     */
    async queryGoods(kind, fromSn, title, status, limit, offset) {
        const params = {};
        
        if (kind !== undefined) {
            params.kind = kind;
        }
        
        if (fromSn !== undefined) {
            params.fromSn = fromSn;
        }
        
        if (title !== undefined) {
            params.title = title;
        }
        
        if (status !== undefined) {
            params.status = status;
        }
        
        if (limit !== undefined) {
            params.limit = limit;
        }
        
        if (offset !== undefined) {
            params.offset = offset;
        }

        return apiClient.get('/api/goods/getGoods', params);
    },

    /**
     * 更新商品信息
     * @param {string} goodsid - 商品ID
     * @param {Object} goodsData - 商品数据
     * @returns {Promise<Object>} 更新结果
     */
    async updateGoods(goodsid, goodsData) {
        return apiClient.put(`/api/goods/updateGoods/${goodsid}`, goodsData);
    },

    /**
     * 删除商品
     * @param {string} goodsid - 商品ID
     * @returns {Promise<Object>} 删除结果
     */
    async deleteGoods(goodsid) {
        return apiClient.delete(`/api/goods/deleteGoods/${goodsid}`);
    }
};
